<?=modules::run('home/top');?>

<body>
<?php
	include_once('function/func.php');
	$cart=$this->session->userdata('Cart');
?>
<div id="wrapper">
	<header>
		<?=modules::run('home/head');?>
	</header>
	
	<nav id="nav">
		<?=modules::run('home/menu')?>
	</nav>
	
	<div class="content">
		<h1>Giỏ hàng</h1>
        <input type="hidden" value="1" id="delCart_check" />
        <?php if($cart){?>
        <div id="show_checkout">
            <div class="checkout right"><a href="<?=PATH_URL.'gio-hang/thanh-toan'?>">Thanh toán</a></div>
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <th></th>
                    <th width="340px">Sản phẩm</th>
                    <th width="135px">Giá</th>
                    <th width="82px">Số lượng</th>              
                    <th width="160px">Tổng cộng</th>
                </tr>
                <?php 
                    $shop=rtrim($cart['shop'],'|');
                    $arrShop=explode('|',$shop);
                    $n=count($arrShop);
                    $prcie_all='';
                    for($i=0;$i<$n;$i++){
                        $arrTmp=explode(',',$arrShop[$i]);
                        $result=$this->productsModel->getOne($arrTmp[0]);
                        if($result[0]->price_new !=0 && $result[0]->promotion !=0){
							$price=$result[0]->price_new * $arrTmp[1];
						}else{
							$price=$result[0]->price_old * $arrTmp[1];
						}
                        $prcie_all +=$price;
                ?>
                <tr>
                    <td><img src="<?=PATH_URL.IMAGES_PRODUCTS.$result[0]->image?>" width="100" height="100" /></td>
                    <td><a href="<?=PATH_URL.'san-pham/chi-tiet/'.$arrTmp[0].''?>"><?=$result[0]->title;?></a></td>
                    <td align="center" class="price">					
						<?php if($result[0]->price_new != 0 && $result[0]->promotion != 0){?>
                            <?=number_format($result[0]->price_new,0,',','.');?> vnđ
                        <?php }else{?>
                            <?=number_format($result[0]->price_old,0,',','.');?> vnđ
                        <?php }?>
                    </td>
                    <td class="cart_num">
                        <input type="text" value="<?=$arrTmp[1]?>" name="" id="qtyCart_<?=$arrTmp[0];?>" />
                        <img title="Cập nhật" onClick="upCart(<?=$arrTmp[0]?>);" src="<?=PATH_URL.'static/images/refresh.png'?>" width="16" height="16" />
                        <img title="Xóa" onClick="delCart(<?=$arrTmp[0]?>);" src="<?=PATH_URL.'static/images/btn_trash.gif'?>" width="16" height="16"/>
                    </td>             
                    <td align="center" class="price"><?=number_format($price,0,',','.');?> vnđ</td>
                </tr>
                <?php }?>
                <tr>
                    <td align="right" colspan="4"><b style="color:#7E8DF8;font-size: 20px">Tổng giá tiền</b></td>
                    <td align="center" class="price"><?=number_format($prcie_all,0,',','.');?> vnđ</td>
                </tr>
                <tr>
                    <td colspan="5">
                        <div class="button left"><a href="<?=PATH_URL?>">Tiếp tục mua hàng</a></div>
                        <div class="button right"><a onClick="eraseCart(); return false;" href="">Xóa giỏ hàng</a></div>
                    </td>
                </tr>
            </table>
        </div>
        <?php }else{?>
        	<h4 class="left" style="margin-top: 20px;width: 100%;">Không có sản phẩm nào trong giỏ hàng của bạn</h4>
            <div class="button right" style="margin-top: 20px;"><a href="<?=PATH_URL?>">Tiếp tục mua hàng</a></div>
        <?php }?>
	</div><!--end content-->
	
	<footer>
		<?=modules::run('home/footer');?>
	</footer>
</div><!--end wrapper-->
</body>
</html>
